import Component, { mixins } from 'vue-class-component'
import { tableMixins } from '@/mixins'
import { subscribeTypeList } from '@/entity/subscribe'
import verifyField from '@/lib/validation/verifyField'

@Component
export default class extends mixins(tableMixins) {
  // ++++++++++ model ++++++++++
  // ++++++++++ props ++++++++++
  // ++++++++++ data ++++++++++
  queryData = this.$Api.appointment.findOneAppointment
  handleFunc = this.$Api.appointment
  searchParams = { id: this.$User.id }
  doctorNames: Array<string> = []
  outpatients: Array<any> = []

  // ++++++++++ computed ++++++++++
  get columns(): Array<IColumn> {
    return [
      { key: 'doctorname', label: '医生', isShowForm: false },
      { key: 'outpatientname', label: '科室', isShowForm: false },
      {
        key: 'u_id', label: '用户ID', default: this.$User.id, isShowTable: false, isShowForm: false,
      },
      {
        key: 'type', label: '预约类型', isShowTable: false, form: {
          type: 'radio', rule: verifyField.common('预约类型不能为空'),
          radio: { key: 'key', label: 'name', data: subscribeTypeList, value: 'key' },
        },
      },
      {
        key: 'doctor', isShowTable: false, label: '医生', form: {
          rule: verifyField.common('医生不能为空'),
          passive: { key: 'type', value: 'doctor' },
          type: 'select',
          select: {
            data: this.doctorNames,
            key: 'id',
            label: 'username',
            value: 'id',
          },
        },
      },
      { key: 'date', label: '预约时间', form: { rule: verifyField.common('预约时间不能为空'), type: 'date-picker', passive: { key: 'type', value: 'date' } } },
      {
        key: 'outpatientid', isShowTable: false, label: '门诊', form: {
          rule: verifyField.common('门诊不能为空'), type: 'select', select: {
            data: this.outpatients,
            key: 'id',
            label: 'outpatientname',
            value: 'id',
          },
        },
      },
      {
        key: 'state', label: '状态', default: 1, form: { isAdd: false }, format: ({ state }) => {
          if (state == "1") {
            return "审核中"
          } else if (state == "2") {
            return "预约成功"
          } else if (state == "3") {
            return "预约失败"
          }
        }
      },
    ]
  }

  // ++++++++++ methods normal ++++++++++
  async once() {
    // 获取医生名字
    const { list } = await this.$Api.user.list({ type: 'doctor' })

    this.doctorNames = [...new Set(list)] as any
    // 获取门诊信息
    const oObj = await this.$Api.outpatient.list({})

    this.outpatients = oObj.list
  }
  // ++++++++++ methods event ++++++++++
  // ++++++++++ Lifecycle Hooks ++++++++++
  // ++++++++++ watch ++++++++++
}
